home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / byacc 1.8.2 / man.page < prev    next >
Encoding:
Text File  |  1993-02-04  |  5.5 KB  |  247 lines  |  [TEXT/R*ch]

  1. '\" t
  2. .\"    %W%    %R% (Berkeley) %E%
  3. .\"
  4. .TH BYACC 1 "January\ 18,\ 1993"
  5. .UC 6
  6. .SH NAME
  7. byacc \- an LALR(1) parser generator
  8. .SH SYNOPSIS
  9. .B byacc [ -CPcdlrtv ] [ -b
  10. .I file_prefix
  11. .B ] [ -p
  12. .I symbol_prefix
  13. .B ]
  14. .I filename
  15. .SH DESCRIPTION
  16. .I byacc
  17. reads the grammar specification in the file
  18. .I filename
  19. and generates an LR(1) parser for it.
  20. The parsers consist of a set of LALR(1) parsing tables and a driver routine
  21. written in the C or Perl programming languages.
  22. .I byacc
  23. normally writes the parse tables and the driver routine to the file
  24. .IR y.tab.c ,
  25. using the C programming language.
  26. .PP
  27. The following options are available:
  28. .RS
  29. .TP
  30. \fB-b \fIfile_prefix\fP
  31. The
  32. .B -b
  33. option changes the prefix prepended to the output file names to
  34. the string denoted by
  35. .IR file_prefix .
  36. The default prefix is the character
  37. .IR y.
  38. .TP
  39. .BR -C " or " -c
  40. Use the C programming language (default).
  41. .TP
  42. .B -d
  43. The \fB-d\fP option causes the header file
  44. .IR y.tab.h
  45. to be written (or
  46. .IR y.tab.ph ,
  47. for Perl).
  48. .TP
  49. .B -l
  50. If the
  51. .B -l
  52. option is not specified,
  53. .I byacc
  54. will insert \#line directives in the generated code.
  55. The \#line directives let the C compiler relate errors in the
  56. generated code to the user's original code.
  57. If the \fB-l\fP option is specified,
  58. .I byacc
  59. will not insert the \#line directives.
  60. \&\#line directives specified by the user will be retained.
  61. .TP
  62. \fB-p \fIsymbol_prefix\fP
  63. Change the prefix in symbols in the generated code to the string 
  64. denoted by \fIsymbol_prefix\fP rather than the default of "\fIyy\fP".
  65. Only symbols generated by \fIbyacc\fP are affected. Symbols in the
  66. definition and user subroutine sections are not changed.
  67. .IP
  68. The \fIsymbol_prefix\fP can contain upper or lower case letters, 
  69. digits, or _ (underline or underscore). It must start with either
  70. an underline or a letter and must contain at least one lower case 
  71. letter.
  72. .IP
  73. All lower case letters in the symbol prefix will be converted to 
  74. upper case letters when defined values or typedefs are generated.
  75. .IP
  76. For example, if '\fB-p\fP ftp_' is specifed on the \fIbyacc\fP command
  77. line:
  78. .in +.5i
  79. .TS
  80. tab (/) box;
  81. a | a .
  82. old symbol/new symbol
  83. =
  84. YYABORT/FTP_ABORT
  85. YYACCEPT/FTP_ACCEPT
  86. YYBYACC/FTP_BYACC
  87. YYDEBUG/FTP_DEBUG
  88. YYSTYPE/FTP_STYPE
  89. yyabort/ftp_abort
  90. yyerrok/ftp_errok
  91. yylex/ftp_lex
  92. yylval/ftp_lval
  93. yyparse/ftp_parse
  94. .TE
  95. .in -.5i
  96. Note: The above list is not complete.
  97. .TP
  98. .B -P
  99. Use the Perl programming language.  The output files have extensions
  100. .I .tab.pl
  101. and
  102. .IR .tab.ph .
  103. .TP
  104. .B -r
  105. The
  106. .B -r
  107. option causes
  108. .I byacc
  109. to produce separate files for code and tables.  The code file
  110. is named
  111. .IR y.code.c,
  112. and the tables file is named
  113. .IR y.tab.c.
  114. In Perl mode, the file name extension is
  115. .IR .pl ,
  116. but the use of this option is not recommended.
  117. .TP
  118. .B -t
  119. The
  120. .B -t
  121. option changes the preprocessor directives generated by \fIbyacc\fP
  122. so that debugging statements will be incorporated in the compiled code.
  123. .TP
  124. .B -v
  125. The
  126. .B -v
  127. option causes a human-readable description of the generated parser to
  128. be written to the file
  129. .IR y.output .
  130. .RE
  131. .PP
  132. If the environment variable TMPDIR is set, the string denoted by
  133. TMPDIR will be used as the name of the directory where the temporary
  134. files are created.
  135. .PP
  136. In C mode, the user's code at the end of the
  137. .SM BYACC
  138. file is inserted before the
  139. .I yyparse
  140. subroutine,
  141. but in Perl mode, it is appended to
  142. .I yyparse
  143. so it can contain the main program.
  144. In Perl mode, there is no library, so the user must
  145. supply the
  146. .I yyerror
  147. and
  148. .I yylex
  149. subroutines and a main program that calls
  150. .IR yyparse .
  151. For example:
  152. .sp
  153. .RS
  154. .nf
  155. %%
  156. .I ...grammar...
  157. %%
  158. sub yyerror { print STDERR "$.: $@\en"; }
  159. sub yylex { ... }
  160. exit &yyparse;
  161. .fi
  162. .RE
  163. .SH FILES
  164. .PD 0
  165. .TP 12
  166. .B y.code.c
  167. output parser code in C
  168. .TP
  169. .B y.tab.c
  170. output parser code and tables in C or, if
  171. .I \-r
  172. switch specified, output parser tables in C
  173. .TP
  174. .B y.tab.h
  175. defines for token names and, if
  176. .I %union
  177. used in grammar, the union definition for C parsers
  178. .TP
  179. .B y.code.pl
  180. output parser code in PERL
  181. .TP
  182. .B y.tab.pl
  183. output parser code and tables in PERL or, if
  184. .I -r
  185. switch specified, output parser tables in PERL
  186. .TP
  187. .B y.tab.ph
  188. PERL assignment statements for token names
  189. .TP
  190. .B y.output
  191. description of parser states, state transitions, and conflicts
  192. .TP
  193. .BR /tmp/byacc.aXXXXXX ",\ " /tmp/byacc.tXXXXXX ",\ " /tmp/byacc.uXXXXXX
  194. temporary files
  195. .TP
  196. .B LIB_DEST/LIBRARY
  197. library containing simple versions of
  198. .I main(\|)
  199. (calls 
  200. .I yyparse(\|)
  201. then exits) and
  202. .I yyerror(\|)
  203. (prints message to
  204. .B stderr
  205. then returns)
  206. .PD
  207. .SH "SEE ALSO"
  208. .BR flex "(1),\ " lex (1)
  209. .LP
  210. .I "Yacc: Yet Another Compiler-Compiler"
  211. .br
  212. Stephen C. Johnson
  213. .br
  214. Originally (?) published as Comp. Sci. Tech. Rep. No. 32. Bell 
  215. Laboratories, July 1975. Reprinted in many different places.
  216. .LP
  217. .I "Introduction to Compiler Construction with UNIX"
  218. .br
  219. Axel T. Schreiner and H. George Friedman, Jr.
  220. .br
  221. Prentice Hall, 1985.
  222. .LP
  223. .I "lex & yacc, Second Edition"
  224. .br
  225. John R. Levine, Tony Mason, and Doug Brown
  226. .br
  227. O'Reilly & Associates, Inc., 1992.
  228. .in +.5i
  229. Possibly the best book yet on lex and yacc. (My opinion only. Others 
  230. may disagree. - Rick Ohnemus)
  231. .in -.5i
  232. .LP
  233. .I "comp.compilers monthly message and Frequently Asked Questions"
  234. .br
  235. Posted monthly in comp.compilers and news.answers USENET newsgroups.
  236. .SH DIAGNOSTICS
  237. If there are rules that are never reduced, the number of such rules is
  238. reported on standard error.
  239. .LP
  240. If there are any LALR(1) conflicts, the number of conflicts is reported
  241. on standard error.
  242. .SH RESTRICTIONS
  243. A symbol prefix specified using the \fB-p\fP switch must contain at least
  244. one lower case character. This is to allow a distinction between variables,
  245. defined values, and typedefs.
  246. .SH BUGS
  247.